// 用于创建一个默认的admin用户
// email 1925541533@qq.com
// password 123456
// xuehao 123456789

const { User } = require("../mod/user")

const {
    setCrypto
} = require('../tool/crypto.js')

const { Jurisdiction } = require("../mod/jurisdiction")

let userdata = {
    shengfen: 2,
    email: '1925541533@qq.com',
    xuehao: '123456789',
    password: '123456'
}
userdata.password = setCrypto(userdata.password)

async function createAdmin() {
    // 先查找admin用户是否已经创建
    let data = await User.findOne(userdata)
    if (data == null) {
        let routerdata = await Jurisdiction.findOne({ user_grade: userdata.shengfen })
        userdata.user_jurisdiction_routerlist = routerdata.jurisdiction_routerlist
        let data1 = await new User(userdata).save()
        if (data1) {
            console.log(`创建默认admin用户成功，xuehao:${userdata.xuehao}，password:123456`)
        }
    }
}

createAdmin()
